package com.example.weli.ble2test;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;

public class BatDisplayView extends View {
    private static final String mString = "Welcome to Mr Wei's blog";
    int cX;
    int cY;
    private Context mContext;
    private Paint mPaint;
    int mPercent = 0;

    public BatDisplayView(Context context) {
        super(context);
    }

    public BatDisplayView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public BatDisplayView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public void set_batPercent(int Percent) {
        this.mPercent = Percent;
        invalidate();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        this.mPaint = new Paint();
        this.mPaint.setColor(Color.rgb(84, 84, 84));
        this.mPaint.setStrokeWidth(3.0f);
        this.mPaint.setStyle(Style.STROKE);
        canvas.drawRect(new Rect(0, 0, this.cX, ((int) (((double) this.cX) * 0.4d)) - 1), this.mPaint);
        canvas.drawRect(new Rect(this.cX, 6, this.cX + 3, ((int) (((double) this.cX) * 0.4d)) - 6), this.mPaint);
        this.mPaint.setStyle(Style.STROKE);
        this.mPaint.setColor(-16777216);
        this.mPaint.setStrokeWidth(1.0f);
        canvas.drawRect(new Rect(2, 2, this.cX - 2, ((int) (((double) this.cX) * 0.4d)) - 2), this.mPaint);
        this.mPaint.setStyle(Style.FILL);
        if (this.mPercent > 7) {
            this.mPaint.setColor(-16711936);
        } else if (this.mPercent > 5) {
            this.mPaint.setColor(-256);
        } else if (this.mPercent > 2) {
            this.mPaint.setColor(-65281);
        } else {
            this.mPaint.setColor(-65536);
        }
        canvas.drawRect(new Rect(3, 3, ((this.cX * this.mPercent) / 10) - 3, ((int) (((double) this.cX) * 0.4d)) - 3), this.mPaint);
        this.mPaint.setColor(-16777216);
        this.mPaint.setTextSize(13.0f);
        canvas.drawText(this.mPercent + "0%", (float) ((int) (((double) this.cX) * 0.12d)), (float) (((int) (((double) this.cX) * 0.4d)) - 4), this.mPaint);
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
        int d = Math.max(getMeasuredWidth(), getMeasuredHeight()) - 5;
        this.cX = d;
        this.cY = d / 2;
    }

    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        setMeasuredDimension(50, 30);
    }
}
